<template>
  <div style="padding: 6px">
    <el-form ref="searchForm" label-width="100px">
      <el-row :gutter="20">
        <el-col :span="6">
          <el-form-item label="订单号">
            <el-input v-model="sd.orderno" size="small" placeholder="订单号" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="提单人">
            <el-input v-model="sd.createusername" size="small" placeholder="提单人" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="礼品名称">
            <el-input v-model="sd.giftName" size="small" placeholder="礼品名称" />
          </el-form-item>
        </el-col>
        <el-col :span="3">
          <el-button class="mt_5" type="primary" size="mini" icon="el-icon-search" @click="searchDaiShenGiftOrder">查询</el-button>
        </el-col>
      </el-row>
    </el-form>

    <el-table :data="shenHeObj.list" border style="width: 100%">
      <el-table-column type="expand" width="50">
        <template v-slot="props">
          <div style="width: 99%;margin: 10px auto" v-if="props.row.giftId === 0">
            <el-divider content-position="left">订单描述</el-divider>
            <div v-html="props.row.descption"></div>
          </div>
          <el-form label-position="left" inline class="form-table" style="padding: 10px;" v-else>
            <el-form-item label="订单号">
              <span>{{ props.row.orderNo }}</span>
            </el-form-item>
            <el-form-item label="礼品分类">
              <span>{{ props.row.typename }}</span>
            </el-form-item>
            <el-form-item label="礼品名称">
              <span>{{ props.row.giftname }}</span>
            </el-form-item>
            <el-form-item label="礼品规格">
              <span>{{ props.row.giftguige }}</span>
            </el-form-item>
            <el-form-item label="礼品品牌">
              <span>{{ props.row.giftpinpai }}</span>
            </el-form-item>
            <el-form-item label="礼品描述">
              <span>{{ props.row.giftdesc }}</span>
            </el-form-item>
            <el-form-item label="订单数量">
              <span>{{ props.row.shuliang }}</span>
            </el-form-item>
            <el-form-item label="需求时间">
              <DateFormat :value="props.row.requireDate" :format="'YYYY-MM-DD'"></DateFormat>
            </el-form-item>
            <el-form-item label="提单人">
              <span>{{ props.row.createusername }}</span>
            </el-form-item>
            <el-form-item label="提单时间">
              <DateFormat :value="props.row.createTime" :format="'YYYY-MM-DD HH:mm'"></DateFormat>
            </el-form-item>
            <el-form-item label="订单描述">
              <el-tooltip :content="props.row.descption" placement="bottom">
                <span>{{ props.row.descption.substring(0, 66) }}</span>
              </el-tooltip>
            </el-form-item>
            <el-form-item label="审核意见">
              <span>{{ props.row.returnReason }}</span>
            </el-form-item>
            <el-form-item label="审核时间">
              <DateFormat :value="props.row.shenheTime" :format="'YYYY-MM-DD HH:mm'"></DateFormat>
            </el-form-item>
            <el-form-item label="礼品模板">
              <el-image :src="baseUrl + props.row.filePath" style="height: 160px" :preview-src-list="props.row.fileList"></el-image>
            </el-form-item>
          </el-form>
        </template>
      </el-table-column>
      <el-table-column label="订单号" prop="orderNo"></el-table-column>
      <el-table-column label="订单类型" width="130">
        <template v-slot="scope">
          <el-tag type="warning" v-if="scope.row.giftId===0">特殊订单</el-tag>
          <el-tag type="success" v-else>礼品订单</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="订单数量" prop="shuliang"></el-table-column>
      <el-table-column label="需求时间" width="150">
        <template v-slot="scope">
          <DateFormat :value="scope.row.requireDate" :format="'YYYY-MM-DD'"></DateFormat>
        </template>
      </el-table-column>
      <el-table-column label="提单人" prop="createusername"></el-table-column>
      <el-table-column label="提单时间">
        <template v-slot="scope">
          <DateFormat :value="scope.row.createTime" :format="'YYYY-MM-DD HH:mm'"></DateFormat>
        </template>
      </el-table-column>
      <el-table-column label="审核意见" prop="returnReason"></el-table-column>
      <el-table-column label="审核时间">
        <template v-slot="scope">
          <DateFormat :value="scope.row.shenheTime" :format="'YYYY-MM-DD HH:mm'"></DateFormat>
        </template>
      </el-table-column>
      <el-table-column label="订单状态" width="130">
        <template v-slot="scope">
          <el-tag type="success" v-if="scope.row.statusId===GiftOrderStatus.shenHePass">{{scope.row.statusname}}</el-tag>
          <el-tag type="danger" v-else-if="scope.row.statusId===GiftOrderStatus.shenHeFail">{{scope.row.statusname}}</el-tag>
          <el-tag v-else>{{scope.row.statusname}}</el-tag>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination v-if="shenHeObj.total>sd.pageSize" class="center" background layout="total, prev, pager, next"
                   @current-change="loadShenHeHistory" :total="shenHeObj.total"
                   :current-page.sync="sd.pageNum" :page-size="sd.pageSize">
    </el-pagination>
  </div>
</template>

<script>
import request from "@/utils/request";
import GiftOrderStatus from "@/utils/GiftOrderStatus";
import {baseURL} from '@/config';
export default {
  data() {
    return {
      GiftOrderStatus: GiftOrderStatus,
      baseUrl: baseURL,
      sd: {
        giftName:"",
        createusername:"",
        pageNum: 1,
        pageSize: 10
      },
      shenHeObj: {},
      entityShenHeVisible : false,
      popupTitle : '',
      popupEntityId : 0,
    }
  },
  mounted() {
    this.loadShenHeHistory()
  },
  methods: {
    searchShenHeHistory(){
      this.sd.pageNum = 1;
      this.loadShenHeHistory();
    },
    loadShenHeHistory() {
      request({
        url: '/gift/ordershenhe/listshenhehistory',
        data: this.sd
      }).then(res => {
        const { data } = res
        this.shenHeObj = data
        this.shenHeObj.list.forEach((g)=>{
          if(g.filePath){
            g.fileList = [baseURL + g.filePath]
          }
        })
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.form-table {
  font-size: 0;
}
.form-table label {
  width: 90px;
  color: #99a9bf;
}
.form-table .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
  width: 50%;
}
</style>
